const arr = [1,2,3]

Array.prototype.myReduce = function(callback, initValue) {
    let preValue = initValue !== undefined ? initValue : this[0]
    const startIndex = initValue !== undefined ? 0 : 1
    for(let i = startIndex; i < this.length; i++) {
        preValue = callback(preValue, this[i], i, this)
    }
    return preValue
}

const res = arr.myReduce((pre,cur) => pre + cur, 0)
console.log(res);
